package com.sdp.wx.task;

import java.util.Map;
import java.util.Map.Entry;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.sdp.right.cron.ScheduledOfTask;
import com.sdp.right.websocket.dto.MessageInfo;
import com.sdp.right.websocket.server.MessageWebsocketServer;
import com.sdp.wx.db.wx_wz_now_num.service.IWxWzNowNumService;
import com.sdp.wx.utils.WxConstants;

@Component
public class WzAlertNumberTask implements ScheduledOfTask{
	
	@Autowired
	private MessageWebsocketServer messageWebsocketServer;
	
	@Autowired
	private IWxWzNowNumService iWxWzNowNumService;

	@Override
	public void execute() {
		Map<String, Map<String, String>> empClientIdMap = MessageWebsocketServer.getEmpClientIdMap();
		if(empClientIdMap==null || empClientIdMap.size()==0) {
			return;
		}
		
		int count = iWxWzNowNumService.wzAlertNumber();
		if(count==0) {
			return;
		}
		
		for (Entry<String, Map<String, String>> entry : empClientIdMap.entrySet()) {
			MessageInfo messageInfo = new MessageInfo();
			messageInfo.setData(count+"个商品库存已经达到预警库存，请注意补充");
			messageInfo.setEmpNo(entry.getKey());
			messageInfo.setType(WxConstants.websocket库存预警.getCode());
			messageWebsocketServer.sendMessage(messageInfo);
		}
	}

}
